<?
include("../../../config/config.php");
include_once('../../../resource/classes/domit/xml_domit_lite_include.php');
$cdCollection =& new DOMIT_Lite_Document();
$newHTML =& new DOMIT_Lite_Document();

$level=1;

function runThroughTheNodes(&$currentNode,&$newHTMLNode,$level){
	global $newHTML;
	$i = 0;
	while ($currentNode != null) {
		if ($currentNode->nodeName!="#text"){
			$nn =& $newHTML->createElement($nm);
		}else{
			$nn =& $newHTML->createTextNode($currentNode->nodeValue);
		}
		$a = null;
		$a = $currentNode->attributes;
		$hasStyle=false;
		if ($a!=null){
			$s="";
			foreach ($a as $key => $val) {
				if (strtolower($key)=="style"){
					$hasStyle=true;
					$s = $val;
				}
				$nn->setAttribute($key,$val);

			}
		}
		$newHTMLNode->appendChild($nn);
		$mcNode =& $newHTMLNode->lastChild;

		if ($hasStyle){
			$newS = explode(";",$s);
			// here we create the font related elements
			if (eregi("background-color",$s)){
				for($u=0;$u<count($newS);$u++){
					if (eregi("background-color",$newS[$u])){
						$c = explode(":",$newS[$u]);
						$mycol=trim($c[1]);
						if ((strtolower($mcNode->nodeName)=="td")||(strtolower($mcNode->nodeName)=="tr")||(strtolower($mcNode->nodeName)=="table")||(strtolower($mcNode->nodeName)=="body"))
						$mcNode->setAttribute("bgcolor",$mycol);
					}
				}
			}
			if (eregi("[^-]color"," ".$s) || eregi("font-size",$s) || eregi("font-family",$s) ){
				$bb=& $newHTML->createElement("font");
				for($u=0;$u<count($newS);$u++){
					if (eregi("[^-]color"," ".$newS[$u])){
						$c = explode(":",$newS[$u]);
						$mycol=trim($c[1]);
						$mycol = eregi("rgb",$mycol)?rgb2hex($mycol):$mycol;
						$bb->setAttribute("color",$mycol);
					}
					if (eregi("font-family"," ".$newS[$u])){
						$c = explode(":",$newS[$u]);
						$bb->setAttribute("face",trim($c[1]));
					}
					if (eregi("font-size",$newS[$u])){
						$c = explode(":",$newS[$u]);
						$tamanho = substr(trim($c[1]),0,strlen(trim($c[1]))-2);
						if ($tamanho<12){
							$mz="1";
						}elseif ($tamanho>11 && $tamanho<16){
							$mz="2";
						}elseif ($tamanho>15 && $tamanho<18){
							$mz="3";
						}elseif ($tamanho>17 && $tamanho<24){
							$mz="4";
						}elseif ($tamanho>23 && $tamanho<32){
							$mz="5";
						}elseif ($tamanho>31 && $tamanho<48){
							$mz="6";
						}elseif ($tamanho>47){
							$mz="7";
						}
						$bb->setAttribute("size",$mz);
					}
				}
				$mcNode->appendChild($bb);
				$mcNode =& $mcNode->lastChild;
			}

			if (eregi("font-weight:"," ".$s)){
				// we need another style here
				$w="";
				for($u=0;$u<count($newS);$u++){
					if (eregi("font-weight",$newS[$u])){
						$c = explode(":",$newS[$u]);
						$stilo = trim($c[1]);
						if (!is_numeric($stilo)){
							switch (strtolower($stilo)){
								case "bold":
								$w="b";
								break;
								case "bolder":
								$w="b";
								break;
								default:
								$w="";
								break;
							}
						}else{
							if ($stilo>450){
								$w="b";
							}else{
								$w="";
							}
						}

					}
				}
				if ($w!=""){
					$bb=& $newHTML->createElement($w);
					$mcNode->appendChild($bb);
					$mcNode =& $mcNode->lastChild;
				}
			}

			if (eregi("font-style"," ".$s)){
				// we need another style here
				$w="";
				for($u=0;$u<count($newS);$u++){
					if (eregi("font-style",$newS[$u])){
						$c = explode(":",$newS[$u]);
						$stilo = trim($c[1]);
						switch (strtolower($stilo)){
							case "italic":
							$w="i";
							break;
							case "oblique":
							$w="i";
							break;
							default:
							$w="";
							break;
						}

					}
				}
				if ($w!=""){
					$bb=& $newHTML->createElement($w);
					$mcNode->appendChild($bb);
					$mcNode =& $mcNode->lastChild;
				}
			}
			if (eregi("text-decoration"," ".$s)){
				// we need another style here
				$w="";
				for($u=0;$u<count($newS);$u++){
					if (eregi("text-decoration",$newS[$u])){
						$c = explode(":",$newS[$u]);
						$stilo = trim($c[1]);
						switch (strtolower($stilo)){
							case "underline":
							$w="u";
							break;
							case "line-through":
							$w="s";
							break;
							default:
							$w="";
							break;
						}

					}
				}
				if ($w!=""){
					$bb=& $newHTML->createElement($w);
					$mcNode->appendChild($bb);
					$mcNode =& $mcNode->lastChild;
				}
			}
		}

		if ($currentNode->hasChildNodes()) {
			runThroughTheNodes(& $currentNode->firstChild,$mcNode,$level+1);
		}
		$currentNode =& $currentNode->nextSibling;
		$i++;
	}
}
$file="/var/www/framework/system/devTools/creator2/example.xml";
$rh = fopen("/var/www/framework/system/devTools/creator2/example.xml", "r");
$newMail = fread($rh, filesize($file));
fclose($rh);

$cdCollection->expandEmptyElementTags(true,array('br','img','input'),array('td'));
$success = $cdCollection->parseXML($newMail, true);

$ar =  $cdCollection->toArray();

// things that are common...
echo "<PRE>";
print_r($ar);
echo "</PRE>";

class project{
	var $array="";
	var $projectName="";
	var $projectVersion="";
	function project($arrayToProcess){
		$this->array=$arrayToProcess;
	}
	function get_project(){
		if (in_array("project",$this->array)){
		
		}
	}
}

?>